#include <sys/_intsup.h>
#include <sys/_stdint.h>
#include "WString.h"
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>


const char* ssid = "123456789";
const char* password = "qwert123";
int tempe;//温度
int cod ;//天气代码
String weather;

String tianqi_qk[]={"Sunny",
	"Clear",
	"Fair",
	"Fair",
	"Cloudy",
	"Partly Cloudy",
	"Partly Cloudy",
	"Mostly Cloudy",
	"Mostly Cloudy",
        "Overcast",
       "Shower",
       "Thundershower",
      "Thundershower with Hail",
	"Light Rain",
	"Moderate Rain",
	"Heavy Rain",
	"Storm",
	"Heavy Storm",
	"Severe Storm",
        "Ice Rain",
       "Sleet",
	"Snow Flurry",
       "Light Snow",
	"Moderate Snow",
	"Heavy Snow",
	"Snowstorm",
	"Dust",
	"Sand",
       "Duststorm",
	"Sandstorm",
	"Foggy",
	"Haze",
	"Windy",
	"Blustery",
	"Hurricane",
	"Tropical Storm",
	"Tornado",
	"Cold",
        "Hot" ,
	"Unknown"
};




String url = "https://api.seniverse.com/v3/weather/now.json?key=";
String city = "北京市";
String your_api_key = "SDpJEv-LjwT2LbC5q";
String ip = "112.19.230.63";

String de_time1 ;
String de_time2 = "null";



void tian_wifi_init (){
  int yyt = 0;
  WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED && yyt<=10) {
    delay(100);
    yyt++;
  }

}


void get_time(){   //苏宁易购的时间

// 创建 HTTPClient 对象
  HTTPClient http;

// 发送GET请求
  http.begin("http://quan.suning.com/getSysTime.do");

  // 获取响应状态码
  int httpCode = http.GET();

  // 获取响应正文
  String response = http.getString();

 http.end();

  // 创建 DynamicJsonDocument 对象
  DynamicJsonDocument doc(1024);

  // 解析 JSON 数据
  deserializeJson(doc, response);

String de_Time1 = doc["sysTime1"].as<String>();
String de_Time2 = doc["sysTime2"].as<String>();

de_time1 = de_Time1;//一串数字
de_time2 = de_Time2;//不同单位间有恒杠


}






void get_ip(){


// 创建 HTTPClient 对象
  HTTPClient http;

// 发送GET请求
  http.begin("https://searchplugin.csdn.net/api/v1/ip/get");

  // 获取响应状态码
  int httpCode = http.GET();

  // 获取响应正文
  String response = http.getString();

 http.end();

  // 创建 DynamicJsonDocument 对象
  DynamicJsonDocument doc(1024);

  // 解析 JSON 数据
  deserializeJson(doc, response);

String IP = doc["data"][ip].as<String>();
ip = IP;



}




void get_city(){

// 创建 HTTPClient 对象
  HTTPClient http;

// 发送GET请求
  http.begin("https://restapi.amap.com/v3/ip?key=ee5649d4c73300e09d7c05be85c321ec&ip="+ip);

  // 获取响应状态码
  int httpCode = http.GET();

  // 获取响应正文
  String response = http.getString();

 http.end();

  // 创建 DynamicJsonDocument 对象
  DynamicJsonDocument doc(1024);

  // 解析 JSON 数据
  deserializeJson(doc, response);

String City = doc["city"].as<String>();//天气代码
city = City;

}



void get_tian_qi(){//从心知天气获取数据

// 创建 HTTPClient 对象
  HTTPClient http;

// 发送GET请求
  http.begin(url+your_api_key+"&location="+city+"&language=zh-Hans&unit=c");

  // 获取响应状态码
  int httpCode = http.GET();

  // 获取响应正文
  String response = http.getString();

 http.end();

  // 创建 DynamicJsonDocument 对象
  DynamicJsonDocument doc(1024);

  // 解析 JSON 数据
  deserializeJson(doc, response);

  // 从解析后的 JSON 文档中获取值
  unsigned int temp = doc["results"][0]["now"]["temperature"].as<unsigned int>();//温度
  unsigned int co = doc["results"][0]["now"]["code"].as<unsigned int>();//天气代码
  String Weather = doc["results"][0]["now"]["text"].as<String>();//天气代码

  weather = Weather;
  tempe = temp;
  cod = co;
  

}























